<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
    <script th:src="@{/plugins/layui/layui.js}"></script>
    <title>驾驶员管理</title>
</head>

<body>
<div class=" page-content">
    <div id="products_style">
        <div class="search_style">

            <ul class="search_content clearfix">
                <li><label class="l_f">物流驾驶员名称</label><input id="dname" name="" type="text"  class="text_add" placeholder="输入驾驶员名称"  style=" width:250px"/></li>
                <li style="width:90px;"><button type="button" id="select" data-type="reload" class="layui-btn layui-btn-blue"><i class="icon-search"></i>查询</button></li>
            </ul>
        </div>
        <div class="border clearfix">
           <span class="l_f">
            <a href="javascript:ovid()" id="driver_add" class="btn btn-warning"><i class="icon-plus"></i>添加驾驶员</a>
           </span>
        </div>
        <table id="demo" lay-filter="demo"></table>
        <script>
            layui.use('table', function(){
                var table = layui.table;
                //第一个实例
                table.render({
                    elem: '#demo'
                    ,url: '/driver/d_list' //数据接口
                    ,page: true //开启分页
                    ,cols: [
                        [ //表头
                            {field: 'tdriverid', title: '驾驶员编号', sort: true}
                            ,{field: 'tdrivername', title: '驾驶员名称'}
                            ,{field: 'tdriveridno', title: '身份证号', sort: true}
                            ,{field: 'tdriversex', title: '性别'}
                            ,{field: 'tdriverphone', title: '联系方式', sort: true}
                            ,{field: 'tdriverlicense', title: '驾驶证号', sort: true}
                            ,{field: 'tdriveryears', title: '工龄', sort: true}
                            ,{field: 'tlogisticsid', title: '物流公司编号', sort: true}
                            ,{fixed: 'right',title: '操作', align:'center', toolbar: '#barDemo'}
                        ]
                    ]
                    ,parseData: function(res){ //res 即为原始返回的数据
                        return {
                            "code":0, //解析接口状态
                            "msg": "", //解析提示文本
                            "count": res.total, //解析数据长度
                            "data": res.records //解析数据列表
                        };
                    }
                });

            });
        </script>
        <script type="text/html" id="barDemo">
            <a title="编辑" class="btn btn-xs btn-info" lay-event="edit"><i class="icon-edit bigger-120"></i></a>
            <a title="删除" class="btn btn-xs btn-warning" lay-event="del"><i class="icon-trash  bigger-120"></i></a>
        </script>
    </div>
</div>
</body>
</html>
<script>
    layui.use('table', function() {
        var table = layui.table;
        var $ = layui.$;
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('请确定是否移除驾驶员', function (index) {
                    $.ajax({
                        url : '/driver/d_delById',
                        type : 'post',
                        data: {'id':data.id},
                        dataType : 'json',                          //表示服务器返回给我们的数据是json格式
                        success : function (data) {
                            if (data) {
                                layui.table.reload("demo");
                            }
                        },

                    })
                    layer.close(index)
                });
            } else if (obj.event === 'edit') {
                var data =$.param(data);
                layer.open({
                    type: 2,
                    title: '编辑驾驶员',
                    maxmin: true,
                    shadeClose:false, //点击遮罩关闭层
                    area : ['600px' , '500px'],
                    content:'/driver/toUpdate?'+data

                });
            }
        });
        $("#select").click(function () {
            var dname = $("#dname").val();
            table.reload('demo',{
                url:'/driver/select'
                ,request:{
                    pageName:'page'
                    ,limitName:'limit'
                }
                ,where:{
                    'tdrivername':dname
                }
                ,page: {
                    curr:1
                }
            })
        });

        $('#driver_add').on('click', function(){
            layer.open({
                type: 2,
                title: '添加驾驶员',
                maxmin: true, //开启最大化最小化按钮
                area: ['600px', '500px'],
                content: "/driver/toAdd"
            });
        });
    });

</script>
